package org.book.dao;

import java.util.List;

import org.book.util.JDBC_Util;


public class UserDaoImp implements UserDao {
	
	@Override
	public boolean remove(int no) {
		String sql = "delete from user where user_id = ?";
		return JDBC_Util.superUpdate(sql, no)!=0;
	}

	@Override
	public boolean add(UserBean stu) {
		String sql = "insert into user(userName,cardNumber) values(?,?)";
		return JDBC_Util.superUpdate(sql, stu.getUserName(), stu.getCardNumber())!=0;
	}

	@Override
	public boolean isEmpty(int no) {
		String sql = "select count(*) from user where user_id = ?";
		return JDBC_Util.superSelect(sql, no)!=0;
	}

	@Override
	public boolean update(int no,UserBean stu) {
		String sql = "update user set userName = ?,cardNumber = ? where user_id = ?";
		return JDBC_Util.superUpdate(sql,stu.getUserName(),stu.getCardNumber(),no)!=0;
	}

	

	@Override
	public UserBean getStuByNo(int no) {
		String sql = "select * from user where user_id = ?";
		return JDBC_Util.superSelect(UserBean.class, sql, no).get(0);
	}

	@Override
	public List<UserBean> getList(int pageCurrent, int pageSize) {
		String sql = "select * from user limit ?,?";
		return JDBC_Util.superSelect(UserBean.class, sql, (pageCurrent-1)*pageSize, pageSize);
	}
	@Override
	public int getCount() {
		String sql = "select count(*) from user";
		return JDBC_Util.superSelect(sql);
	}

	@Override
	public List<UserBean> getLike(String str) {
		String s = '%'+str+'%';
		String sql = "SELECT *\r\n" + 
				"FROM user\r\n" + 
				"WHERE user_id LIKE ?\r\n" + 
				"OR userName LIKE ?\r\n" + 
				"OR cardNumber LIKE ?";
		return JDBC_Util.superSelect(UserBean.class, sql, s,s,s);
	}

}
